package org.yibinxueyuan.drawcard.pojo;

import org.apache.ibatis.type.Alias;

/**
 * 分页数据绑定
 */
@Alias(value = "Paging")
public class Paging {
    private int page = -1;   //第几页
    private int size = -1;   //每页查询几条数据
    private int totalNumber = -1; //总数据条数
    private int totalPage = -1;   //总页数
    private int first = -1;      //数据库中起始位置
    private String cardName = null; //抽卡的名字,查询使用

    public String getCardName() {
        return cardName;
    }

    public void setCardName(String cardName) {
        this.cardName = cardName;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public int getTotalNumber() {
        return totalNumber;
    }

    public void setTotalNumber(int totalNumber) {
        this.totalNumber = totalNumber;
    }

    public int getTotalPage() {
        //如果页数大小,和 总的数据条数都知道了,就求出总页数
        if(totalNumber != -1 && size != -1){
            if(totalNumber%size == 0){
                totalPage = totalNumber/size;
            }else{
                totalPage = totalNumber/size + 1;
            }
        }
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getFirst() {
        //如果第几页和页面大小知道了就求出数据库中分页的起始数据
        if(page != -1 && size != -1){
            first = (page - 1) * size;
        }
        return first;
    }

    public void setFirst(int first) {
        this.first = first;
    }


    @Override
    public String toString() {
        return "Paging{" +
                "page=" + page +
                ", size=" + size +
                ", totalPage=" + totalPage +
                ", first=" + first +
                '}';
    }
}
